//
//  AddressViewController.m
//  NewProject
//
//  Created by 王嘉琪 on 2017/6/11.
//  Copyright © 2017年 李航飞. All rights reserved.
//

#import "AddressViewController.h"

@interface AddressViewController ()<UITextFieldDelegate>
@property (nonatomic, strong)UITextField *contactText;
@property (nonatomic, strong)UITextField *phoneText;
@property (nonatomic, strong)UITextField *cityText;
@property (nonatomic, strong)UITextField *addressText;
@property (nonatomic, strong)UITextField *doorNumText;
@property (nonatomic, strong)UIImageView *manImg;
@property (nonatomic, strong)UIImageView *womanImg;
@property (nonatomic, strong)NSString *show;
@property (nonatomic, assign)NSInteger *tagInteger;
@end

@implementation AddressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _show=@"1";
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"新增地址";
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(rightItem:)];
    
//    self.navigationController.navigationBar.tintColor  = [UIColor blueColor];
    //rightItem setTitleTextAttributes: forState:<#(UIControlState)#>
    self.navigationItem.rightBarButtonItem = rightItem;
    self.navigationItem.rightBarButtonItem.tintColor=ALL_COLOR;

    [self setUpview];
}

-(void)rightItem:(UIBarButtonItem *)item{
    NSLog(@"222222222");
}

- (void)setUpview{
    
    self.contactText = [[UITextField alloc] init];
    self.contactText.tag = 100;
    UIView *contactView = [self setUpViewWithTitle:@"联 系 人" WithPlaceStr:self.contactText];
    self.contactText.placeholder = @"收货人姓名";
    contactView.frame = CGRectMake(0, 64+ 15*kScrenHidth, self.view.frame.size.width, 60*kScrenHidth);
    [self.view addSubview:contactView];
    
    UIView *xingBie = [[UIView alloc] initWithFrame:CGRectMake(0, 64+ 15*kScrenHidth + 60*kScrenHidth, self.view.frame.size.width, 60*kScrenHidth)];
    [self.view addSubview:xingBie];
    UILabel *lineLable = [[UILabel alloc] init];
    lineLable.backgroundColor = LINE_COLOE_223;
    lineLable.frame = CGRectMake(10*kScrenWidth, 59*kScrenHidth, WIDTH - 20*kScrenWidth, 1);
    [xingBie addSubview:lineLable];
    UIImageView *manImg=[[UIImageView alloc] initWithFrame:CGRectMake(100*kScrenWidth, 20*kScrenHidth, 20*kScrenWidth, 20*kScrenWidth)];
    [manImg setImage:[UIImage imageNamed:@"zeng-02x2"]];
    [xingBie addSubview:manImg];
    _manImg=manImg;
    
    UILabel *manLab=[[UILabel alloc] initWithFrame:CGRectMake(manImg.frame.size.width+manImg.frame.origin.x+20*kScrenWidth, 20*kScrenHidth, 35*kScrenWidth, 20*kScrenHidth)];
    manLab.text=@"先生";
    manLab.textColor=BTN_TITLE_COLOR;
    manLab.font=[UIFont systemFontOfSize:14];
    [xingBie addSubview:manLab];
    UIButton *manBtn=[[UIButton alloc] initWithFrame:CGRectMake(100*kScrenWidth, 0, 75*kScrenWidth, 60*kScrenHidth)];
    [xingBie addSubview:manBtn];
    manBtn.tag=2000;
    _tagInteger=2000;
    [manBtn addTarget:self action:@selector(man:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *womanImg=[[UIImageView alloc] initWithFrame:CGRectMake(manLab.frame.size.width+manLab.frame.origin.x+40*kScrenWidth, 20*kScrenHidth, 20*kScrenWidth, 20*kScrenWidth)];
    [womanImg setImage:[UIImage imageNamed:@"zeng-01x2"]];
    [xingBie addSubview:womanImg];
    _womanImg=womanImg;
    UILabel *womanLab=[[UILabel alloc] initWithFrame:CGRectMake(womanImg.frame.size.width+womanImg.frame.origin.x+20*kScrenWidth, 20*kScrenHidth, 35*kScrenWidth, 20*kScrenHidth)];
    womanLab.text=@"女士";
    womanLab.textColor=BTN_TITLE_COLOR;
    womanLab.font=[UIFont systemFontOfSize:14];
    [xingBie addSubview:womanLab];
    UIButton *womanBtn=[[UIButton alloc] initWithFrame:CGRectMake(manBtn.frame.size.width+manBtn.frame.origin.x+50, 0, 75*kScrenWidth, 60*kScrenHidth)];
    [xingBie addSubview:womanBtn];
    womanBtn.tag=1000;
    [womanBtn addTarget:self action:@selector(man:) forControlEvents:UIControlEventTouchUpInside];
    
    self.phoneText = [[UITextField alloc] init];
    self.phoneText.tag = 200;
    self.phoneText.keyboardType = UIKeyboardTypeNumberPad;
    UIView *phonoView = [self setUpViewWithTitle:@"手机号码" WithPlaceStr:self.phoneText];
    self.phoneText.placeholder = @"请输入手机号";
    phonoView.frame = CGRectMake(0, 64+ 15*kScrenHidth + 120*kScrenHidth, self.view.frame.size.width, 60*kScrenHidth);
    [self.view addSubview:phonoView];
    
    self.cityText = [[UITextField alloc] init];
    self.cityText.tag = 200;
    UIView *cityView = [self setUpViewWithTitle:@"所在城市" WithPlaceStr:self.cityText];
    self.cityText.placeholder = @"沈阳";
    cityView.frame = CGRectMake(0, 64+ 15*kScrenHidth + 180*kScrenHidth, self.view.frame.size.width, 60*kScrenHidth);
    [self.view addSubview:cityView];
    
    self.addressText = [[UITextField alloc] init];
    self.addressText.tag = 300;
    UIView *addressView = [self setUpViewWithTitle:@"收货地址" WithPlaceStr:self.addressText];
    self.addressText.placeholder = @"和泰大厦";
    addressView.frame = CGRectMake(0, 64+ 15*kScrenHidth + 240*kScrenHidth, self.view.frame.size.width, 60*kScrenHidth);
    [self.view addSubview:addressView];
    
    self.doorNumText = [[UITextField alloc] init];
    self.doorNumText.tag = 400;
    UIView *doorView = [self setUpViewWithTitle:@"门牌号" WithPlaceStr:self.doorNumText];
    self.doorNumText.placeholder = @"请输入您的门牌号等详细信息";
    doorView.frame = CGRectMake(0, 64+ 15*kScrenHidth + 300*kScrenHidth, self.view.frame.size.width, 60*kScrenHidth);
    [self.view addSubview:doorView];
    
}


- (UIView *)setUpViewWithTitle:(NSString *)title WithPlaceStr:(UITextField *)textView{
    
    UIView *backView = [[UIView alloc] init];
    backView.backgroundColor = [UIColor whiteColor];
    
    UILabel *lable = [[UILabel alloc] init];
    lable.frame = CGRectMake(15*kScrenWidth, 10*kScrenHidth, 80*kScrenWidth, 40*kScrenHidth);
    lable.textColor = [UIColor blackColor];
    lable.text = title;
    lable.font=[UIFont systemFontOfSize:14];
    [backView addSubview:lable];
    
    textView.frame = CGRectMake(100*kScrenWidth, 10*kScrenHidth, 200*kScrenWidth, 40*kScrenHidth);
    textView.delegate = self;
    textView.font=[UIFont systemFontOfSize:14];
    
    [backView addSubview:textView];
    
    UILabel *lineLable = [[UILabel alloc] init];
    lineLable.backgroundColor = LINE_COLOE_223;
    lineLable.frame = CGRectMake(10*kScrenWidth, 59*kScrenHidth, WIDTH - 20*kScrenWidth, 1);
    [backView addSubview:lineLable];
    return backView;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField.tag == 100) {
        NSLog(@"!!!");
    }
    if (textField.tag == 200) {
        NSLog(@"!2!");
    }
    if (textField.tag == 300) {
        NSLog(@"!3!");
    }
    if (textField.tag == 400) {
        NSLog(@"!4!");
    }
    
}
- (void)man:(UIButton *)btn{
    NSLog(@"%@",btn);
    if(_tagInteger!=btn.tag){
        if ([_show isEqualToString:@"1"]) {
            [_womanImg setImage:[UIImage imageNamed:@"zeng-02x2"]];
            [_manImg setImage:[UIImage imageNamed:@"zeng-01x2"]];
            _show=@"0";
        }else if([_show isEqualToString:@"0"]){
            [_womanImg setImage:[UIImage imageNamed:@"zeng-01x2"]];
            [_manImg setImage:[UIImage imageNamed:@"zeng-02x2"]];
            _show=@"1";
        }
    }
    _tagInteger=btn.tag;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
